script_enemy_main{

let survivalcirclesize=1;
let survivalcirclespin=1;

let phase=1;
let angle1=90+rand(-20,20);
let color=1;
let radius=0;

let character="Masahiro";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=81;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEfocus=("script\SoundEffects\charge1.wav");
let SEshotm3=("script\SoundEffects\shotm3.wav");

let BG1=("\script\Images\BackgroundLayers\Masahiro1.png");
let BG2=("\script\Images\BackgroundLayers\Masahiro2.png");
let BG3=("\script\Images\OtherEffects\SpellCircle1a.png");
let GRboss=("\script\Images\CharacterSprites\Masahiro.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsMasahiro1.txt");

	LoadSE("script\SoundEffects\charge1.wav");
	LoadSE("script\SoundEffects\shotm3.wav");
	
	LoadGraphic("\script\Images\BackgroundLayers\Masahiro1.png");
	LoadGraphic("\script\Images\BackgroundLayers\Masahiro2.png");
	LoadGraphic("\script\Images\OtherEffects\SpellCircle1a.png");
	LoadGraphic("\script\Images\CharacterSprites\Masahiro.png");

	SetScore(2500000);
	SetLife(500);
	SetTimer(90);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);

	SetDurableSpellCard;
}
	
@MainLoop{

SetShotAutoDeleteClip(300,300,300,300);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=0; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Philosopher's Stone [Panacea]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


if(frame>=120 && frame%50==0 && phase==1 && color<=10){
	loop(3){
	let angle2=0;
	let shot1=0;
		loop(73){
		CreateShotA(shot1,cx,cy,0);
		SetShotDataA(shot1,0,1.5,angle1+angle2,0,0,0,96+color);
		FireShot(shot1);
		angle2+=1.5;
		}
	angle1+=360/3;
	}
angle1+=rand(30,50);
PlaySE(SEshotm3);
if(color==10){ phase++; frame=0; color=1; }
color++;
}

if(frame>=120 && frame%30==0 && phase==2 && color<=10){
	loop(3){
	let angle2=0;
	let shot1=0;
		loop(70){
		CreateShotA(shot1,cx,cy,0);
		SetShotDataA(shot1,0,2,angle1+angle2,0,0,0,96+color);
		FireShot(shot1);
		angle2+=1.5;
		}
	angle1+=360/3;
	}
angle1+=rand(20,30);
PlaySE(SEshotm3);
if(color==10){ phase++; frame=0; color=1; }
color++;
}

if(frame>=120 && frame%10==0 && phase==3 && color<=10){
	loop(3){
	let angle2=0;
	let shot1=0;
		loop(67){
		CreateShotA(shot1,cx,cy,0);
		SetShotDataA(shot1,0,3,angle1+angle2,0,0,0,96+color);
		FireShot(shot1);
		angle2+=1.5;
		}
	angle1+=360/3;
	}
angle1+=rand(10,15);
PlaySE(SEshotm3);
if(color==10){ phase++; frame=0; color=1; }
color++;
}

//==================================================================

if(frame>=120 && frame%120==0 && phase==4 && color<=10){
	loop(3){
	let angle2=0;
	let shot1=0;
		loop(50){
		CreateShotA(shot1,GetPlayerX+80*cos(angle1+angle2),GetPlayerY+80*sin(angle1+angle2),20);
		SetShotDataA(shot1,0,0,angle1+angle2+180,0,0.02,0.5,96+color);
		FireShot(shot1);
		angle2+=1.5;
		}
	angle1+=360/3;
	}
angle1+=rand(25,50);
PlaySE(SEshotm3);
if(color==10){ phase++; frame=0; color=1; }
color++;
}

if(frame==180 && phase==5){ DeleteEnemyShot(ALL); }
if(frame>=240 && frame%120==0 && phase==5 && color<=10){
	loop(3){
	let angle2=0;
	let shot1=0;
		loop(50){
		CreateShotA(shot1,GetPlayerX+80*cos(angle1+angle2),GetPlayerY+80*sin(angle1+angle2),20);
		SetShotDataA(shot1,0,0,angle1+angle2+180,0,0.02,0.5,96+color);
		FireShot(shot1);
		CreateShotA(shot1,GetPlayerX+150*cos(angle1+angle2+180),GetPlayerY+150*sin(angle1+angle2+180),20);
		SetShotDataA(shot1,0,0,angle1+angle2,0,0.03,1,96+color);
		SetShotKillTime(shot1,165);
		FireShot(shot1);
		angle2+=1.5;
		}
	angle1+=360/3;
	}
angle1+=rand(25,50);
PlaySE(SEshotm3);
if(color==10){ phase++; frame=0; color=1; }
color++;
}

//==================================================================

if(frame==120 && phase==6){ DeleteEnemyShot(ALL); }
if(frame>=150 && frame%90==0 && phase==6 && color<=10){
	loop(3){
	let angle2=0;
	let shot1=0;
		loop(65){
		CreateShotA(shot1,cx,cy,20);
		SetShotDataA(shot1,0,1.3,angle1+angle2+180,0,-0.0036,-0.65,96+color);
		FireShot(shot1);
		angle2+=1.5;
		}
	angle1+=360/3;
	}
angle1+=rand(30,90);
PlaySE(SEshotm3);
color+=1;
}
if(frame==1060 && phase==6){
	let angle2=0;
	let shot1=0;
		loop(250){
		CreateShotA(shot1,cx+290*cos(angle2),cy+290*sin(angle2),20);
		SetShotDataA(shot1,0,0.3,angle2+180,0,0,0,108);
		SetShotKillTime(shot1,965);
		FireShot(shot1);
		angle2+=360/250;
		}
}


if(frame==60){
	SetColor(0,255,128);
	Concentration01(90);
	SetColor(255,255,255);
	PlaySE(SEfocus);
}


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<200){ bgfade+=5; }

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(2,2);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,-time/2);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0,0,400,400);
	SetGraphicScale(1,1);
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,time/2);
	DrawGraphic(cx,cy);

if(survivalcirclesize>0){
	SetGraphicRect(0,0,200,200);
	SetGraphicScale(survivalcirclesize*1.4,survivalcirclesize*1.4);
	SetTexture(BG3);
	SetAlpha(bgfade*0.85);
	SetColor(70+60*cos((time+0)/2),70+60*cos((time+120)/2),70+60*cos((time+240)/2));
	SetGraphicAngle(0,0,survivalcirclespin*1.2);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0,0,200,200);
	SetGraphicScale(survivalcirclesize*2,survivalcirclesize*2);
	SetTexture(BG3);
	SetAlpha(bgfade*0.85);
	SetColor(170+60*cos((time+0)/2),170+60*cos((time+120)/2),170+60*cos((time+240)/2));
	SetGraphicAngle(0,0,-survivalcirclespin*0.7);
	DrawGraphic(cx,cy);
}
survivalcirclespin++;
if(GetLife<=0 && survivalcirclesize>0){ survivalcirclesize-=0.03; }
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	if(GotSpellCardBonus){ SetCommonData("LastTrumpCard",14); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}